import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1

Rectangle {
    height: bgImage.height
    color: "#428BCA"
    anchors.right: parent.right
    anchors.rightMargin: 0
    anchors.left: parent.left
    anchors.leftMargin: 0
    anchors.bottom: parent.bottom
    anchors.bottomMargin: 0

    property alias title: titleText.text
    property bool canGoBack: true
    property alias goBackText: btnBack.text
    property real proporcao: 0.5

    property Component topButtonStyle: ButtonStyle {
        label: Text {
            antialiasing: true
            renderType: Text.NativeRendering
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            text: control.text
            font.bold: true
            font.pixelSize: app.height * 0.022
            color: "white"
        }
        background: Rectangle {
            antialiasing: true
            implicitWidth: 100
            implicitHeight: 25
            border.width: control.activeFocus ? 2 : 1
            border.color: "white"
            radius: 4
            color: control.pressed ? "gray" : "transparent"
        }
    }

    Image {
        id: bgImage
        height: 128*proporcao
        anchors.left: parent.left
        anchors.right: parent.right
        source: "qrc:/images/bottom.png"
        fillMode: Image.TileHorizontally
    }

    Button {
        id: btnBack
        height: parent.height * 0.4
        width: parent.width * 0.19
        visible: true
        text: qsTr("Desligar")
        anchors.bottom: parent.bottom
        anchors.bottomMargin: parent.width * 0.01
        anchors.left: parent.left
        anchors.leftMargin: parent.width * 0.01
        style: topButtonStyle
        onClicked: {
            if (canGoBack) {
                stackView.pop({immediate: true});
            } else {
                confirmar_desligamento();
            }
        }
    }

    Button {
        id: btnAtualizar
        height: parent.height * 0.4
        width: parent.width * 0.19
        visible: !canGoBack
        text: qsTr("Atualizar")
        anchors.bottom: parent.bottom
        anchors.bottomMargin: parent.width * 0.01
        anchors.right: parent.right
        anchors.rightMargin: parent.width * 0.01
        style: topButtonStyle
        onClicked: {
            stackView.clear();
            recarregar_dados();
        }
    }

    Text {
        id: titleText
        color: "#ffffff"
        text: qsTr("")
        font.bold: true
        anchors.left: btnBack.right
        anchors.leftMargin: parent.width * 0.01
        anchors.verticalCenter: parent.verticalCenter
        font.pixelSize: parent.height * 0.3
    }

//    Rectangle {
//        height: 3
//        width: parent.width
//        color: (appSkin.horizontalSeparatorColor=="")?header.color:appSkin.horizontalSeparatorColor;
//        anchors.left: parent.left
//        anchors.right: parent.right
//        anchors.bottom: parent.bottom
//    }
}

